package diancan.JDK;

//import net.sf.cglib.proxy.InvocationHandler;
import org.apache.log4j.Logger;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class TakeawayJDK implements InvocationHandler {

    private Logger logger = Logger.getLogger(TakeawayJDK.class);
    private Object target;  // 代理对象


    public TakeawayJDK(Object target) {
        this.target = target;
    }

    /**
     *
     * @param proxy 是正在执行下面invoke方法的代理对象
     * @param method  是正在被调用的接口fff
     * @param args 是传递给接口方法的参数
     * @return
     * @throws Throwable
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("使用JDK动态代理");
        Object object = method.invoke(target, args);
        before();
        after();
        return "订单信息"+object;

    }
    public void before(){
        System.out.println("===== 前置准备 =====");
        System.out.println("下单完成！准备做菜中...");
        System.out.println("召唤骑手上门取餐！");
        logger.info("前置准备完成（做菜+召唤骑手）");
    }
    public void after(){
        System.out.println("===== 后置配送 =====");
        System.out.println("骑手已取餐，正在配送...");
        System.out.println("餐品送达！拍照留证发送给客户～");
        logger.info("订单配送完成");
    }
}
